package com.baoli.blzj.utils;

import android.app.Activity;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.jude.rollviewpager.RollPagerView;

/**
 * 计算控件高度封装类 by John on 17/7/1.
 */

public class CustomCalcHeightUtils {

    public int screenWidth = 0;

    public static CustomCalcHeightUtils getInstance() {
        CustomCalcHeightUtils cc = new CustomCalcHeightUtils();
        return cc;
    }

    public RollPagerView setHeight(RollPagerView v, Activity context,int num) {
        DisplayMetrics metric = new DisplayMetrics();
        context.getWindowManager().getDefaultDisplay().getMetrics(metric);
        screenWidth = metric.widthPixels;
        RelativeLayout.LayoutParams linearParams = (RelativeLayout.LayoutParams) v.getLayoutParams();
        linearParams.width = screenWidth;
        linearParams.height = screenWidth / 10 * num;//为轮播图适应各个尺寸手机比例
        v.setLayoutParams(linearParams); //使设置好的布局参数应用到控件
        return v;
    }
    public RelativeLayout setHeight(RelativeLayout v, Activity context,int num) {
        DisplayMetrics metric = new DisplayMetrics();
        context.getWindowManager().getDefaultDisplay().getMetrics(metric);
        screenWidth = metric.widthPixels;
        LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) v.getLayoutParams();
        linearParams.width = screenWidth;
        linearParams.height = num;//为轮播图适应各个尺寸手机比例
        v.setLayoutParams(linearParams); //使设置好的布局参数应用到控件
        return v;
    }
}
